package com.zhang.publisher;

import com.zhang.publisher.bean.ProductStats;
import com.zhang.publisher.service.ProductStatsService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @title:
 * @author: zhang
 * @date: 2022/3/17 13:06
 */
@RestController
public class TestController {
    @Autowired
    private ProductStatsService productStatsService;

    @RequestMapping("/test")
    public List<ProductStats> test(@RequestParam(value = "data", defaultValue = "0") Integer date,
                       @RequestParam(value = "limit", defaultValue = "10") Integer limit){

        if (date == 0) {
            date = now();
        }
        List<ProductStats> productStats = productStatsService.selectProductStatsByCategory3(date, limit);
        return productStats;
    }


    private Integer now() {
        String date = DateFormatUtils.format(new Date(), "yyyyMMdd");
        return Integer.valueOf(date);
    }
}
